package pub.tbc.atps.util.okhttp.builder;

import com.squareup.okhttp.Headers;
import pub.tbc.toolkit.Loops;
import pub.tbc.toolkit.function.BiConsumer;

import java.util.Map;

/**
 * @author tbc on 2016/12/2 13:20:05.
 */
public class HttpHeaderBuilder {
    Headers.Builder headersBuilder = new Headers.Builder();

    private HttpHeaderBuilder() {

    }

    public static HttpHeaderBuilder builder() {
        return new HttpHeaderBuilder();
    }

    public HttpHeaderBuilder handlers(Map<String, String> headers) {
        Loops.forEach(headers, new BiConsumer<String, String>() {
            @Override
            public void accept(String k, String v) {
                headersBuilder.add(k, v);
            }
        });
        return this;
    }

    public HttpHeaderBuilder add(String name, String value) {
        headersBuilder.add(name, value);
        return this;
    }


    public Headers build() {
        return headersBuilder.build();
    }
}
